
package com.example.demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class VerificationCodeService {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    public boolean verifyCode(String phoneNumber, String codeType, String code) {
        String storedCode = redisTemplate.opsForValue().get(getCodeKeyByType(phoneNumber, codeType));
        return storedCode != null && storedCode.equals(code);
    }

    private String getCodeKeyByType(String phoneNumber, String codeType) {
        return "verificationCode:" + codeType + ":" + phoneNumber;
    }
}
